﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

#include "BSTree.h"

void test1()
{
	int a[] = { 8, 3, 1, 10, 6, 4, 7, 14, 13 };
	int b[] = {8,3,1,6,4,7};
	int c[] = { 8 };
	wnf::BSTree<int> tree;
	//for (const auto& e : a)
	//{
	//	tree.InsertR(e);
	//}
	for (int i = 8; i >= 0; i--)
	{
		tree.InsertR(a[i]);
	}


	tree.InOrder();
	//for(int i = 8;i >= 0;i--)
	//{
	//	tree.erase(a[i]);
	//	tree.InOrder();
	//}
}

class date
{
public:
	date(int year, int month)
		:_year(year)
		, _month(month)
	{}
	int _year;
	int _month;
};

void test2()
{
	string arr[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜", "苹果", "香蕉", "苹果", "香蕉" };
	key_value::BSTree<string, int> countTree;
	for (const auto& str : arr)
	{
	// 先查找⽔果在不在搜索树中
	// 1、不在，说明⽔果第⼀次出现，则插⼊<⽔果, 1>
	// 2、在，则查找到的结点中⽔果对应的次数++
	//BSTreeNode<string, int>* ret = countTree.Find(str);
	auto ret = countTree.find(str);
	if (ret == NULL)
	{
		countTree.InsertR(str, 1);
	} 
	else
	{
		ret->_value++;
	}
	} 
	countTree.InOrder();
	countTree.~BSTree();
}

void test3()
{
	key_value::BSTree<string, string> dict;
	//BSTree<string, string> copy = dict;
	dict.Insert("left", "左边");
	dict.Insert("right", "右边");
	dict.Insert("insert", "插入");
	dict.Insert("string", "字符串");
	string str;
	while (cin >> str)
	{
		auto ret = dict.find(str);
		if (ret)
		{
			cout << "->" << ret->_value << endl;
		} 
		else
		{
			cout << "无此单词，请重新输入" << endl;
		}
	}
	dict.~BSTree();
}


int main()
{
	//test1();
	test2();
	test3(); 
	return 0;
}